﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace Minotaur.App.Core.Validation
{
    /// <summary>
    /// 租户编号必填验证
    /// </summary>
    public class UnitCodeRequeridValidationRule : ValidationRule
    {

        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (string.IsNullOrEmpty(value + ""))
            {
                return new ValidationResult(false, "租户编码不能为空！");
            }
            return new ValidationResult(true, null);
        }
    }
    /// <summary>
    /// 用户账号必填验证
    /// </summary>
    public class AccountRequeridValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (string.IsNullOrEmpty(value + ""))
            {
                return new ValidationResult(false, "用户账号不能为空！");
            }
            return new ValidationResult(true, null);
        }
    }
    /// <summary>
    /// 用户密码必填验证
    /// </summary>
    public class PassworsRequeridValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (string.IsNullOrEmpty(value + ""))
            {
                return new ValidationResult(false, "密码不能为空！");
            }
            return new ValidationResult(true, null);
        }
    }

    /// <summary>
    /// 中文名验证-菜单
    /// </summary>
    public class MenuCNNameRequeridValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (string.IsNullOrEmpty(value + ""))
            {
                return new ValidationResult(false, "菜单中文名不能为空！");
            }
            if ((value + "").Length > 50)
                return new ValidationResult(false, "菜单中文名不能超过50个字符");
            Regex regex = new Regex("^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z0-9-]){1,50}$", RegexOptions.IgnoreCase);
            if (!regex.IsMatch($"{value}"))
                return new ValidationResult(false, "菜单名称中只能包含中文英文字符和数字");
            return new ValidationResult(true, null);
        }
    }
    /// <summary>
    /// 中文名验证-菜单
    /// </summary>
    public class MenuENNameRequeridValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (string.IsNullOrEmpty(value + ""))
            {
                return new ValidationResult(false, "菜单英文名不能为空！");
            }
            if ((value + "").Length > 100)
                return new ValidationResult(false, "菜单英文名不能超过100个字符");
            Regex regex = new Regex("^([a-zA-Z0-9- ]){1,100}$", RegexOptions.IgnoreCase);
            if (!regex.IsMatch($"{value}"))
                return new ValidationResult(false, "菜单名称中只包含英文字符和数字");
            return new ValidationResult(true, null);
        }
    }
    /// <summary>
    /// 中文名验证-菜单
    /// </summary>
    public class MenuCodeRequeridValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (string.IsNullOrEmpty(value + ""))
            {
                return new ValidationResult(false, "菜单编码不能为空！");
            }
            if ((value + "").Length > 20)
                return new ValidationResult(false, "菜单编码不能超过20个字符");
            Regex regex = new Regex("^([a-zA-Z0-9]){1,20}$", RegexOptions.IgnoreCase);
            if (!regex.IsMatch($"{value}"))
                return new ValidationResult(false, "菜单名称中只包含英文字符和数字");
            return new ValidationResult(true, null);
        }
    }
}
